import { Component, OnInit } from '@angular/core';
import {ApiUrl} from "../../../../config/api-url";
import {BaseService} from "../../../../shared/service/base.service";
import {LayerService} from "../../../../shared/service/layer.service";
import {AppReuseStrategy} from "../../../../layout/app-reuse-strategy";

@Component({
  selector: 'app-log-app',
  templateUrl: './log-app.component.html',
  styleUrls: ['./log-app.component.less']
})
export class LogAppComponent implements OnInit {
  // 加载动画
  isSpinning: boolean;
  list:any;
  deviceNo:string = "";
  type:string = "1";
  dirIndex:number = 99;

  constructor(public baseService: BaseService,
              public layerService: LayerService) { }

  ngOnInit(): void {
  }

  toSearch(){
    //99 代表主目录
    this.findList(this.dirIndex);
  }
  // 获取列表
  findList(dirIndex) {
    if(this.deviceNo ==""){
      return this.layerService.messageError("设备号不能为空");
    }
    this.isSpinning = true;
    let body = {
      deviceNo: this.deviceNo,
      dirIndex: dirIndex,
      type:this.type
    }
    this.baseService.post(ApiUrl.DeviceUrl + '/findAppLogDirList',body).subscribe(
      data => {
        this.isSpinning = false;
        if (data.status == 0) {
          this.list = data.data;
        } else {
          this.baseService.layer.messageError(data.msg);
        }
      }
    );
  }

  /**
   * 通知app下载日志文件
   */
  noticeDownloadFile(index,item){
    if(item.type == 1){
      this.dirIndex = index;
      this.findList(index);
      return
    }
    this.layerService.modalConfirm('提示', confirm => {
      if (confirm) {
        let body = {
          deviceNo: this.deviceNo,
          dirIndex: this.dirIndex,
          index: index
        }

        this.baseService.post(ApiUrl.DeviceUrl + '/noticeDownloadFile',body).subscribe(
          data => {
            if (data.status == 0) {
              this.baseService.layer.messageSuccess("发送成功，请前往160服务器查看");
            } else {
              this.baseService.layer.messageError(data.msg);
            }
          }
        );
      }
    }, '确定要通知设备下载该日志文件吗？');
  }

}
